﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities.PBKT;
using Entities;

namespace WindowsForms.PBKT
{
    public partial class FormThemLichThiDau : Form
    {
        public bool trangThai = false;
        public FormThemLichThiDau()
        {
            InitializeComponent();
            grpDSCauThu.Enabled = trangThai;
         
        }

        

        private void btnLuu_Click(object sender, EventArgs e)
        {
            var tk = TrongTai.Objects.GetById("TT_002");
            if (!trangThai)
            {


            }
        }
        
        private void dgvDSTrongTai_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (dgvDSTrongTai.CurrentCell.ColumnIndex == 2)
            {
                var source = new AutoCompleteStringCollection();
//                String[] stringArr = Array.ConvertAll<DataRow, String>(TrongTai.Objects.All()
//, delegate(DataRow row)
//                {
//                    return (String)row["TenTrongTai"];
//                });

                TextBox ttCod = e.Control as TextBox;
                if (ttCod != null)
                {
                    ttCod.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                    ttCod.AutoCompleteCustomSource = source;
                    ttCod.AutoCompleteSource = AutoCompleteSource.CustomSource;

                }
            }
        }

        private void dgvDSTrongTai_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            dvgCbb.ValueMember = "MaTT";
            dvgCbb.DisplayMember = "TenTrongTai";
            dvgCbb.DataSource = TrongTai.Objects.All().ToList();
            
        }

        private void dgvDSTrongTai_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {     

            DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvDSTrongTai.Rows[e.RowIndex].Cells[e.ColumnIndex];
            MessageBox.Show(cell.Value.ToString());
            TrongTai tt = TrongTai.Objects.GetById(cell.Value);
            if (e.ColumnIndex == 2)
            {
                MessageBox.Show(tt.TenTrongTai);
            }
            
        }


    }
}
